<template>
    <div class="navBar">
        <div class="down_bj" v-show="isShow" @click="handleMenu"></div>
        <!-- 导航栏 -->
        <van-nav-bar
        :title="title"
        fixed
        placeholder
        z-index="998"
        >   
            <template #left>
                <van-image v-show="goBack && !isTouch" width="17" height="17" fit="contain" :src="require('assets/images/BackIcon.png')" @click="handleGoBack" />
                <span v-if="!isCollectionPage" v-show="isTouch || isOperation" class="selectAll" @click="handleCancel">取消</span>
            </template>
            <template #right>
                <div class="navBar_right">
                    <div class="down_menuBox" v-if="menuShow">
                        <span v-if="isCollectionPage" class="selectAll" @click="handleAddCollection">添加到</span>
                        <van-image v-else v-show="!isTouch" width="17" height="17" fit="contain" :src="require('assets/images/operation.png')" @click="handleMenu" />
                        <!-- 文件下拉菜单 -->
                        <div class="down_menu" v-show="isShow" v-if="isDocument">
                            <van-uploader :preview-image="false" :show-upload="true" :after-read="handleUpload">
                                <div class="down_list">
                                    <van-image width="12" height="12" fit="contain" :src="require('assets/images/upload-icon.png')" />
                                    <span class="down_title van-ellipsis">上传</span>
                                </div>
                            </van-uploader>
                            <div class="down_list" @click="handleNewFileClick">
                                <van-image width="12" height="12" fit="contain" :src="require('assets/images/edit-icon.png')" />
                                <span class="down_title van-ellipsis">新建</span>
                            </div>
                        </div>
                        <!-- 收藏下拉菜单 -->
                        <div class="down_menu" v-show="isShow" v-if="isFavourite">
                            <div class="down_list" @click="handleListAddClick">
                                <van-image width="12" height="12" fit="contain" :src="require('assets/images/add-icon.png')" />
                                <span class="down_title van-ellipsis">添加</span>
                            </div>
                            <div class="down_list" @click="handleListEditClick">
                                <van-image width="12" height="12" fit="contain" :src="require('assets/images/edit-icon.png')" />
                                <span class="down_title van-ellipsis">编辑</span>
                            </div>
                            <div class="down_list" @click="handleListDeleteClick">
                                <van-image width="12" height="12" fit="contain" :src="require('assets/images/delete-icon.png')" />
                                <span class="down_title van-ellipsis">删除</span>
                            </div>
                        </div>
                    </div>
                    
                    <span v-if="isAllCheck" v-show="isTouch" class="selectAll" @click="handleIsCheck">全选</span>
                </div>
            </template>
        </van-nav-bar>
        <!-- 搜索 -->
        <van-search
        class="searchDom"
        v-if="isSearch"
        v-model="searchValue"
        placeholder="搜索"
        shape="round"
        clearable
        show-action
        @search="onSearch"
        @cancel="onCancel"
        >
            <template #action>
                <van-image
                class="searchItem"
                v-show="isCalendar"
                width="29" height="29"
                fit="contain" :src="require('assets/images/Calendar.png')"
                @click="CalendarVisible = true"
                />
                <van-image
                class="searchItem"
                v-show="isHighSearch"
                width="29" height="29"
                fit="contain" :src="require('assets/images/isHighSearch.png')"
                @click="HighSearchClick"
                />
                <div class="searchItem" @click="onCancel">取消</div>
            </template>
        </van-search>
        <!-- 搜索占位 -->
        <div class="searchDom_palceholder" style="height: 54px;" v-if="isSearch"></div>

        <!-- 新建文件夹dialog -->
        <van-dialog
        class="newFileDialog"
        v-model="newFileDialogVisible"
        title="新建文件夹"
        show-cancel-button
        closeOnClickOverlay
        @confirm="handleConfirmClick"
        >
            <van-field v-model="newFileDialogValue" placeholder="添加文件夹" />
        </van-dialog>

        <!-- 日历 -->
        <van-calendar v-model="CalendarVisible" type="range" :min-date="minDate" show-confirm @confirm="onConfirm" />

        <!-- 高级搜索 -->
        <van-popup v-model="HighSearchVisible" position="bottom" round >
            <van-nav-bar
            class="HighSearchTop"
            title="高级搜索"
            left-text="取消"
            right-text="完成"
            @click-left="HighSearchVisible = false"
            @click-right="onClickRight"
            />

            <div class="highSearchContent">
                <van-form>
                    <!-- 文件名/关键字 -->
                    <van-field
                        v-model="fileName"
                        name="文件名/关键字"
                        label="文件名/关键字"
                    />
                    <!-- 文档类型 -->
                    <van-field name="highSearchRadio" label="文档类型">
                        <template #input>
                            <van-checkbox-group v-model="highSearchRadioVal" direction="horizontal">
                                <van-checkbox name="doc" icon-size="14px" class="checkboxClass">doc</van-checkbox>
                                <van-checkbox name="ppt" icon-size="14px" class="checkboxClass">ppt</van-checkbox>
                                <van-checkbox name="txt" icon-size="14px" class="checkboxClass">txt</van-checkbox>
                                <van-checkbox name="pdf" icon-size="14px" class="checkboxClass">pdf</van-checkbox>
                                <van-checkbox name="xls" icon-size="14px" class="checkboxClass">xls</van-checkbox>
                            </van-checkbox-group>
                        </template>
                    </van-field>
                    <!-- 自定义类型 -->
                    <van-field
                    readonly
                    clickable
                    name="chooseType"
                    :value="chooseTypeVal"
                    label="自定义类型"
                    @click="chooseTypeVisible = true"
                    />
                    <van-popup v-model="chooseTypeVisible" position="bottom">
                        <van-picker
                            show-toolbar
                            :columns="columnsList"
                            @confirm="chooseTypeConfirm"
                            @cancel="chooseTypeVisible = false"
                        />
                    </van-popup>

                    <!-- 自定义类型增加选项 -->
                    <div
                    class="Dynamic_item"
                    v-for="(item) in dynamicItem"
                    :key="item.id"
                    >
                        <van-field
                        v-model="item.value"
                        :name="item.attributeCn"
                        :label="item.attributeCn"
                        v-if="item.dataType == 2"
                        />
                        <van-field
                        readonly
                        clickable
                        name="chooseType"
                        :value="item.value"
                        :label="item.attributeCn"
                        @click="chooseTypeClick(item)"
                        v-else-if="item.dataType == 1"
                        />
                        <van-popup v-model="item.visible" position="bottom">
                            <van-datetime-picker
                            type="date"
                            title="选择年月日"
                            :formatter="formatter"
                            @confirm="chooseTypeConfirm2($event,item)"
                            @cancel="item.visible = false"
                            />
                        </van-popup>
                        
                    </div>

                </van-form>
            </div>
        </van-popup>


    </div>
</template>

<script>
export default {
    name: 'navBar',
    props: {
        title: {
            type: String,
            default: ''
        },
        leftText: {
            type: String,
            default: ''
        },
        fatherIsTouch: {
            type: Boolean,
            default: false
        },
        // 是否显示返回箭头
        goBack: {
            type: Boolean,
            default: false
        },
        // 是否显示右侧下拉操作菜单
        fatherIsShow: {
            type: Boolean,
            default: false
        },
        // 是否加载右侧菜单功能
        menuShow: {
            type: Boolean,
            default: false
        },
        // 是否为文件页面
        isDocument: {
            type: Boolean,
            default: false
        },
        // 是否为收藏页面
        isFavourite: {
            type: Boolean,
            default: false
        },
        // 是否显示全选按钮
        isAllCheck: {
            type: Boolean,
            default: false
        },
        // 是否显示搜索框
        isSearch: {
            type: Boolean,
            default: true
        },
        // 是否为收藏页, 用于默认显示添加到和取消隐藏
        isCollectionPage: {
            type: Boolean,
            default: false
        },
        // parentId, 用于上传功能
        parentId: {
            type: Number,
            default: 0
        },
        // 当前选中的treeId
        currentTreeId: {
            type: Number,
        },
        // 从哪个页面进来的，用于判断搜索接口
        form: {
            type: String,
            default: '文件'
        },
        // 搜索是否加入日历功能
        isCalendar: {
            type: Boolean,
            default: false
        },
        // 搜索是否加入高级搜索功能
        isHighSearch: {
            type: Boolean,
            default: false
        },
        // 目录id， 用于进入文件夹返回
        DirectoryIdArr: {
            type: Array,
            default: function(){
                return []
            }
        }
    },
    data(){
        return{
            searchValue: '',
            // iscancel: false
            isTouch: this.fatherIsTouch,
            isShow: this.fatherIsShow,
            
            // 是否显示取消操作
            isOperation: false,

            //新建文件夹dialog
            newFileDialogVisible: false,
            newFileDialogValue: '',

            // 日历控件
            CalendarVisible: false,
            CalendarValue: [],

            // 高级搜索
            HighSearchVisible: false,
            fileName: '',
            highSearchRadioVal: [],
            chooseTypeVisible: false,
            chooseTypeVal: '',
            columnsList: [],
            // 自定义类型中间变量
            columnsListId: [],

            dynamicItem: [],

            sonDirectoryIdArr: []
        }
    },
    methods: {
        // 左侧点击事件
        handleGoBack(){
            this.sonDirectoryIdArr = this.DirectoryIdArr
            // this.sonDirectoryIdArr = sessionStorage.getItem('DirectoryIdArr').split(',')
            // console.log('返回')
            console.log(this.sonDirectoryIdArr)
            if(this.sonDirectoryIdArr.length <= 1){
                this.$router.goBack()
            }else{
                this.sonDirectoryIdArr.pop()
                this.$emit('handleGoBack', this.sonDirectoryIdArr)
                // console.log('目录返回')
            }
                
        },
        // 左侧取消事件
        handleCancel(){
            
            // 如果是作用于操作菜单的取消
            if(this.isOperation){
                this.isOperation = false
                this.$emit('sonEditClick', this.isOperation)
            }else{
                this.isTouch = false
                this.$emit('cancelClick', false)
            }
        },
        // 右侧菜单点击事件
        handleMenu(){
            this.isShow = !this.isShow
        },
        // 菜单新建文件夹操作事件
        handleNewFileClick(){
            this.newFileDialogVisible = true
        },
        // 提交新建文件夹
        handleConfirmClick(){
            if(this.newFileDialogValue.trim() == '') return;
            this.$request({
                method: 'post',
                url: '/api/General/InsertDirectory?Token=' + sessionStorage.getItem("mobileToken"),
                data: {
                    DirectoryName: this.newFileDialogValue,
                    DirectoryId: this.DirectoryIdArr[this.DirectoryIdArr.length - 1]
                }
            }).then(({data}) => {
                if(data.code == 200){
                    this.$emit('handleNewFileClick', true)
                    this.$notify({type:'success', message: data.msg})
                }else{
                    this.$notify({type:'danger', message: data.msg})
                }
                this.isShow = false
            })
        },

        // 菜单添加操作事件
        handleListAddClick(){
            this.$emit('sonAddClick', true)
        },
        // 菜单编辑操作事件
        handleListEditClick(){
            this.isOperation = true
            this.$emit('sonEditClick', this.isOperation)
        },
        // 右侧菜单删除事件
        handleListDeleteClick(){
            this.isOperation = true
            this.$emit('sonDeleteClick', this.isOperation)
        },
        // 右侧全选事件
        handleIsCheck(){
            this.$emit('checkClick', true)
        },
        // 右侧收藏添加到事件
        handleAddCollection(){
            this.$emit('handleAddCollection', true)
        },
        // 上传
        handleUpload(file){
            let formdata = new window.FormData();
            formdata.append("file",file.file);
            formdata.append("parentId",this.parentId)
            // formdata.append("headers","{'Content-Type': 'multipart/form-data'}");
            this.$request({
                url: '/api/General/UploadFile?Token=' + sessionStorage.getItem("mobileToken"),
                method: 'post',
                data: formdata,
                headers: { 
                    'Content-Type': 'multipart/form-data'
                }
                
            }).then(({data}) => {
                if(data.code == 200){
                    this.$emit('onCancel', true)
                    this.$notify({type:'success', message: data.msg})
                }else{
                    this.$notify({type:'danger', message: data.msg})
                }
            })
        },
        // 搜索框点击跳转搜索页面
        // handleSearchClick(){
        //     // console.log(this.currentTreeId)
        //     this.$router.push({name: 'Search', params: {currentTreeId: this.currentTreeId}})
        // },
        // 提交搜索
        onSearch(){
            // if (event.keyCode == 13) { //如果按的是enter键 13是enter 
            //     event.preventDefault(); //禁止默认事件（默认是换行） 
            //     console.log(event.target.value)
            //     this.$notify({type:'danger', message: '点击了确认'})
            // }
            // this.$notify({type:'danger', message: '点击了确认'})
            switch(this.form){
                case '知识库': 
                    this.KnowledgeSearch();
                    break;
                case '收藏': 
                    this.FavouriteSearch();
                    break;
                case '我的分享':
                    this.MyShareSearch();
                    break;
                case '好友分享':
                    this.FriendShareSearch();
                    break;
                case '个人文档':
                    this.getRecentDocuments();
                    break;
                case '部门文档':
                    this.getdepartment();
                    break;
                case '群组文档':
                    this.getgroup();
                    break;
                case '公共文档':
                    this.getpublic();
                    break;
                case '我的审核':
                    this.getexamine();
                    break;
                case '回收站':
                    this.getrecycle();
                    break;
            }
            
        },
        // 知识库搜索
        KnowledgeSearch(){
            this.$request({
                method: 'get',
                url: '/api/KnowledgeTree/GetKnowledgeTreeByTreeId',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    treeId: this.currentTreeId,
                    Name: this.searchValue,
                    FileCategory: '全部',
                    pageSize: 10,
                    pageIndex: 1
                }
            }).then(({data}) => {
                if(data.code == 200){
                    let listData = data.knowledgeTreeFileList
                    this.$emit('onSearch', listData)
                }else{
                    this.$notify(data.msg)
                }
            })
        },
        // 收藏搜索
        FavouriteSearch(){
            this.$request({
                method: 'get',
                url: '/api/FavouriteTree/GetFavouriteTreeByTreeId',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    treeId: this.currentTreeId,
                    Name: this.searchValue,
                    FileCategory: '全部',
                    pageSize: 10,
                    pageIndex: 1
                }
            }).then(({data}) => {
                if(data.code == 200){
                    let listData = data.favouriteTreeFileList
                    this.$emit('onSearch', listData)
                }else{
                    this.$notify(data.msg)
                }
            })
        },
        // 我的分享搜索
        MyShareSearch(){
            this.$request({
                method: 'get',
                url: '/api/Shared/GetShared',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    Bodystr: this.searchValue,
                    TimeStart: String(this.CalendarValue[0]),
                    TimeSipt: String(this.CalendarValue[1]),
                    pageSize: 10,
                    pageIndex: 1
                }
            }).then(({data}) => {
                if(data.code == 200){
                    let listData = data.dataList
                    listData.forEach(item => {
                        let splitCreateTimeArr = item.createTime.split('T')
                        let splitExpiresTimeArr = item.expiresTime.split('T')
                        item.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        item.expiresTime = splitExpiresTimeArr[0] + ' ' + splitExpiresTimeArr[1]
                    })
                    this.$emit('onSearch', listData)
                }else{
                    this.$notify(data.msg)
                }
            })
        },
        // 好友分享搜索
        FriendShareSearch(){
            this.$request({
                method: 'get',
                url: '/api/Shared/GetSharedMessage',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    Bodystr: this.searchValue,
                    TimeStart: String(this.CalendarValue[0]),
                    TimeSipt: String(this.CalendarValue[1]),
                    pageSize: 10,
                    pageIndex: 1
                }
            }).then(({data}) => {
                if(data.code == 200){
                    let listData = data.dataList
                    listData.forEach(item => {
                        let splitCreateTimeArr = item.happendTime.split('T')
                        let splitExpiresTimeArr = item.expiresTime.split('T')
                        item.happendTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        item.expiresTime = splitExpiresTimeArr[0] + ' ' + splitExpiresTimeArr[1]

                    })
                    this.$emit('onSearch', listData)
                }else{
                    this.$notify(data.msg)
                }
            })
        },
        // 个人文档搜索
        getRecentDocuments() {
            this.$request({
                method: "get",
                url: "/api/RecentDocument/GetPersonalDocuments",
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    DirectoryId: "", //目录ID
                    Name: this.searchValue, //搜索
                    PageIndex: 1,
                    PageSize: 10,
                    StartTime: String(this.CalendarValue[0]),
                    EndTime: String(this.CalendarValue[1])
                }
            }).then(({ data }) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData) 
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            });
        },
        // 部门文档搜索
        getdepartment() {
            this.$request({
                method: "get",
                url: "/api/DepartmentDocument/GetDepartmentDocuments",
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    DirectoryId: "", //目录ID
                    Name: this.searchValue, //搜索
                    PageIndex: 1,
                    PageSize: 10,
                    StartTime: String(this.CalendarValue[0]),
                    EndTime: String(this.CalendarValue[1])
                }
            }).then(({ data }) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData) 
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            });
        },
        // 群组文档搜索
        getgroup() {
            this.$request({
                method: "get",
                url: "/api/GroupownerDocument/GroupownerDocuments",
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    DirectoryId: "", //目录ID
                    Name: this.searchValue, //搜索
                    PageIndex: 1,
                    PageSize: 10,
                    StartTime: String(this.CalendarValue[0]),
                    EndTime: String(this.CalendarValue[1])
                }
            }).then(({ data }) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData) 
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            });
        },
        // 公共文档搜索
        getpublic() {
            this.$request({
                method: "get",
                url: "/api/PublicDocument/GetPublicDocuments",
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    DirectoryId: "", //目录ID
                    Name: this.searchValue, //搜索
                    PageIndex: 1,
                    PageSize: 10,
                    StartTime: String(this.CalendarValue[0]),
                    EndTime: String(this.CalendarValue[1])
                }
            }).then(({ data }) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData) 
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            });
        },
        // 我的审核搜索
        getexamine() {
            this.$request({
                method: "get",
                url: "/api/Approval/GetApprovalDocuments",
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    DirectoryId: "", //目录ID
                    Name: this.searchValue, //搜索
                    PageIndex: 1,
                    PageSize: 10,
                    StartTime: String(this.CalendarValue[0]),
                    EndTime: String(this.CalendarValue[1])
                }
            }).then(({ data }) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData) 
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            });
        },
        // 回收站搜索
        getrecycle() {
            this.$request({
                method: "get",
                url: "/api/Recycle/GetRecycle",
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    DirectoryId: "", //目录ID
                    Name: this.searchValue, //搜索
                    PageIndex: 1,
                    PageSize: 10,
                    StartTime: String(this.CalendarValue[0]),
                    EndTime: String(this.CalendarValue[1])
                }
            }).then(({ data }) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData) 
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            });
        },
        // 日历控件选择事件
        onConfirm(arr){
            // console.log(arr)
            // console.log(arr[0].getTime())
            arr[0] = this.formatDate(arr[0].getTime())
            arr[1] = this.formatDate(arr[1].getTime())

            this.CalendarValue = arr
            // console.log(this.CalendarValue)
            this.CalendarVisible = false
            this.onSearch()
        },
        // 搜索取消事件
        onCancel(){
            console.log('取消')
            this.searchValue = ''
            this.$emit('onCancel', true)
        },
        // 时间转换函数
        formatDate(time){
            function addZero(num) {
                return num < 10 ? '0' + num : num;
            }
            let date = new Date(time);
            let year = date.getFullYear();
            let month = addZero(date.getMonth() + 1);
            let day = addZero(date.getDate());

            return `${year}-${month}-${day}`
        },
        // 展开高级搜索
        HighSearchClick(){
            this.$request({
                url: '/api/General/GetFileTypes',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                }
            }).then(({data}) => {
                if(data.code == 200){
                    this.columnsListId = data.data
                    // this.columnsList.forEach(item => {
                    //     // item.values = item.fileTypeName
                    //     return item.fileTypeName
                    // })
                    this.columnsList = data.data.map(item => item.fileTypeName)
                }else{
                    this.$notify({type:'danger', message: data.msg})
                }
            })
            this.HighSearchVisible = true
        },
        // 自定义类型弹窗选择确定事件
        chooseTypeConfirm(val, index){
            this.chooseTypeVal = val
            // 选中值的fileTypeId
            let fileTypeId = this.columnsListId[index].fileTypeId
            this.$request({
                url: '/api/General/GetFileTypeList',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    fileTypeId 
                }
            }).then(({data}) => {
                if(data.code == 200){
                    this.dynamicItem = data.data.fileTypeAttributeList
                    // 添加选择器控制隐藏属性
                    // this.dynamicItem.forEach(item => {
                    //     if(item.dataType == 1){
                    //         // item.visible = false
                    //         this.$set(item, 'visible', false)
                    //     }
                    // })
                    // console.log(this.dynamicItem)
                }else{
                    this.$notify({type:'danger', message: data.msg})
                }
            })
            this.chooseTypeVisible = false
        },
        // 当为时间类型时， 点击弹出选择器
        chooseTypeClick(item){
            item.visible = true
        },
        // 当为时间类型时，确定指定时间
        chooseTypeConfirm2(value,item){
            // console.log(item)
            // console.log(value)
            
            item.value = this.formatDate(value)
            item.visible = false
        },
        // 格式化时间，用于显示
        formatter(type, val){
            if (type === 'year') {
                return `${val}年`;
            } else if (type === 'month') {
                return `${val}月`;
            } else if (type == 'day') {
                return `${val}日`;
            }

            return val;
        },
        // 高级搜索提交
        onClickRight(){
            switch(this.form){
                case '个人文档':
                    this.personalSearch();
                    break;
                case '部门文档':
                    this.departmentSearch();
                    break;
                case '群组文档':
                    this.groupSearch();
                    break;
                case '公共文档':
                    this.publicSearch();
                    break;
            }
        },
        // 个人文档更多搜索提交事件
        personalSearch(){
            this.$request({
                method: 'post',
                url: '/api/RecentDocument/SearchPersonalDocuments?Token='  + sessionStorage.getItem("mobileToken"),
                data: {
                    SearchName: this.fileName,
                    FileCategory: this.highSearchRadioVal,
                    FileTypeAttributes: this.dynamicItem,
                    PageIndex: 1,
                    PageSize: 10
                }
            }).then(({data}) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData)
                    this.HighSearchVisible = false
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            })
        },
        // 部门文档更多搜索提交事件
        departmentSearch(){
            this.$request({
                method: 'post',
                url: '/api/DepartmentDocument/SearchDepartmentDocuments?Token='  + sessionStorage.getItem("mobileToken"),
                data: {
                    SearchName: this.fileName,
                    FileCategory: this.highSearchRadioVal,
                    FileTypeAttributes: this.dynamicItem,
                    PageIndex: 1,
                    PageSize: 10
                }
            }).then(({data}) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }

                    })
                    this.$emit('onSearch', listData)
                    this.HighSearchVisible = false
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            })
        },
        // 群组文档更多搜索提交事件
        groupSearch(){
            this.$request({
                method: 'post',
                url: '/api/GroupownerDocument/SearchGroupownerDocuments?Token='  + sessionStorage.getItem("mobileToken"),
                data: {
                    SearchName: this.fileName,
                    FileCategory: this.highSearchRadioVal,
                    FileTypeAttributes: this.dynamicItem,
                    PageIndex: 1,
                    PageSize: 10
                }
            }).then(({data}) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    this.$emit('onSearch', listData)
                    this.HighSearchVisible = false
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            })
        },
        // 公共文档更多搜索提交事件
        publicSearch(){
            this.$request({
                method: 'post',
                url: '/api/PublicDocument/SearchPublicDocuments?Token='  + sessionStorage.getItem("mobileToken"),
                data: {
                    SearchName: this.fileName,
                    FileCategory: this.highSearchRadioVal,
                    FileTypeAttributes: this.dynamicItem,
                    PageIndex: 1,
                    PageSize: 10
                }
            }).then(({data}) => {
                if (data.code == 200) {
                    let listData = data.dataList
                    // 时间转化
                    listData.forEach(item => {
                        let splitCreateTimeArr = []
                        if(item.eFileResultType == 1){
                            splitCreateTimeArr = item.cloudDirectoryInfo.createTime.split('T')
                            item.cloudDirectoryInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }else{
                            splitCreateTimeArr = item.cloudFileInfo.createTime.split('T')
                            item.cloudFileInfo.createTime = splitCreateTimeArr[0] + ' ' + splitCreateTimeArr[1]
                        }
                        // 文件或文件夹类型判断
                        switch(item.eFileResultType){
                            case 0:
                                item.eFileResultType = 1;break;
                            case 1:
                                item.eFileResultType = 2;break;
                        }
                    })
                    console.log(listData)
                    this.$emit('onSearch', listData)
                    this.HighSearchVisible = false
                } else {
                    this.$toast.fail("加载数据失败，请重试。");
                }
            })
        }
    },
    computed: {
        minDate(){
            let date = new Date()
            let before = date.setMonth(date.getMonth()-6)
            return new Date(before)
        }
    },
    watch: {
        '$route': {
            deep: true,
            handler(to, from){
                // console.log(to, from)
                // if(to.)
                // 控制左上角返回箭头
            }
        },
        fatherIsTouch(newVal){
            this.isTouch = newVal
        },
        fatherIsShow(newVal){
            this.isShow = newVal
        },
        newFileDialogVisible(newVal){
            if(!newVal){
                this.newFileDialogValue = ''
            }
        },
        // CalendarVisible(newVal){
        //     if(!newVal){
        //         this.CalendarValue = []
        //     }
        // },
        HighSearchVisible(newVal){
            if(!newVal){
                this.fileName = ''
                this.highSearchRadioVal = []
                this.dynamicItem = []
            }
        }
    }
}
</script>

<style lang="less" scoped>
.navBar /deep/ .van-nav-bar{
    height: 44px;
}
.navBar /deep/ .van-nav-bar__title{
    font-size: 18px;
    color: #2a2b2d;
    font-weight: 600;
}
.navBar /deep/ .van-search{
    padding: 10px 15px;
}

.selectAll{
    color: #0099ff;
    font-size: 14px;
}
.navBar /deep/ [class*=van-hairline]::after{
    border: none;
    box-shadow: 0 1px 1px 1px #f8f8f8;
}

.down_bj{
    background-color: rgba(0, 0, 0, 0);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 998;
}
.searchDom{
    position: fixed;
    top: 44px;
    left: 0;
    right: 0;
    z-index: 100;
}

.searchDom /deep/ .van-search__action{
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0;
    background-color: #fff;
}
.searchItem{
    margin: 0 6px;
}
.navBar_right{
    display: flex;
    justify-content: center;
    align-items: center;
    .down_menuBox{
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
        .down_menu{
            position: absolute;
            top: calc(100% + 10px);
            right: -5px;
            background-color: #fff;
            border-radius: 4px;
            box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
            padding: 0 10px;
            &::after{
                content: '';
                display: block;
                position: absolute;
                top: -10px;
                right: 8%;
                z-index: 9000;
                border: 5px solid #fff;
                border-left-color: transparent;
                border-right-color: transparent;
                border-top-color: transparent;
                box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
            }
            .down_list{
                border-bottom: 1px solid #f1f1f1;
                padding: 9px 14.5px;
                display: flex;
                align-items: center;
                .down_title{
                    font-size: 12px;
                    color: #2a2b2d;
                    margin-left: 5px;
                }
            }
        }
    }
    
}

.HighSearchTop{
    
}
.highSearchContent{
    padding: 40px 0 30px;
}
.checkboxClass{
    margin-right: 13px;
}
.checkboxClass /deep/ .van-checkbox__label{
    margin-left: 3px;
}
</style>